package com.atguigu.eduservice.controller;


import com.aiguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author Y丶HS练习谷粒商城
 * @since 2022-10-09
 */
@Api(description = "评论业务")
@RestController
@RequestMapping("/eduservice/educomment")
public class EduCommentController {
    /**
     * 评论服务
     */
    @Resource
    private EduCommentService eduCommentService;

    /**
     * 获取评论信息
     * @param limit
     * @param page
     * @param courseId
     * @return
     */
    @ApiOperation("获取评论信息")
    @GetMapping("/listEntity/{page}/{limit}")
    public R getEntityList(
            @ApiParam(name = "limit", value = "页码大小", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "courseId", value = "课程id", required = false)
            String courseId
    ){

        Page<EduComment> commentPage = new Page<>(page,limit);
        Map<String, Object> map = eduCommentService.listEntityByCourseId(commentPage,courseId);
        return R.ok().data(map);
    }

    @ApiOperation("保存评论信息")
    @PostMapping("/saveEntity")
    public R saveEntity(@RequestBody EduComment entity, HttpServletRequest request){
        String token = request.getHeader("token");
        eduCommentService.saveEntity(entity,token);
        return R.ok();
    }
}

